/*
 * @(#)Mp3Player.java
 * 
 * Copyright(C) 2004 Yujin Kim
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.netexplode.jtunes.model.player;

import com.netexplode.jtunes.client.player.jTunes;
import com.netexplode.jtunes.core.Configuration;
import com.netexplode.jtunes.model.media.CollectionManager;
import com.netexplode.jtunes.model.media.MediaFile;

/**
 * <code>Mp3Player</code> represents .....
 * 
 * @author ykim
 * @version $Revision: 1.1 $
 * @since 0.1
 */
public class Mp4Player extends ThreadedMediaPlayer {

	// private static final Log log = LogFactory.getLog(Mp4Player.class);

	// protected static PlayerControl player;

	private Configuration configuration;

	protected CollectionManager collectionManager;

	protected PlayerManager playerManager;

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	public void setCollectionManager(CollectionManager collectionManager) {
		this.collectionManager = collectionManager;
	}

	public void setPlayerManager(PlayerManager playerManager) {
		this.playerManager = playerManager;
	}

	protected synchronized void initPlayer(MediaFile mediaFile) throws PlayerException {
		// if (player == null) {
		// }
	}

	public synchronized void play() throws PlayerException {
		// final MediaFile mediaFile = CollectionManager
		// .getInstance()
		// .getCurrentMediaFile();
		// try {
		// if (mediaFile instanceof Mp3File) {
		// player = PlayerFactory.createMPEG4Player();
		// player.open(mediaFile.getFile().getAbsolutePath());
		// player.start();
		// }
		// else if (mediaFile instanceof ItunesFile) {
		// final ItunesFile itunesFile = (ItunesFile) mediaFile;
		// final MediaCollection col = CollectionManager
		// .getInstance()
		// .getCurrrentCollection();
		// if (col instanceof SharedCollection) {
		// final SharedCollection shared = (SharedCollection) col;
		// final String requestString = "databases/"
		// + itunesFile.getTrack().getDatabaseId()
		// + "/items?session-id="
		// + shared.getConnection().getSessionId()
		// +
		// "&meta=dmap.itemid,dmap.itemname,daap.songalbum,daap.songartist,daap.songtracknumber,daap.songuserrating,daap.songgenre,daap.songformat,daap.songtime";
		// player.open(shared.getConnection().getServerName()
		// + "/"
		// + requestString);
		// }
		// }
		// }
		// catch (MalformedURLException e) {
		// throw new PlayerException(e);
		// }
		// catch (IOException e) {
		// throw new PlayerException(e);
		// }
	}

	public synchronized void play(MediaFile mediaFile) throws PlayerException {
		initPlayer(mediaFile);
		if (super.thread == null) {
			super.thread = new Thread(this, "Player Thread");
			initPlayer(mediaFile);
			super.thread.start();
		}
		playerManager.setPlaying(true);
		jTunes.setLcdPanelText();
	}

	public synchronized void stop() throws PlayerException {
		// if (player != null) {
		// player.stopUrl();
		// }
		// player = null;
		// if (super.thread != null) {
		// super.thread = null;
		// }
		playerManager.setPlaying(false);
	}

	/* THREAD HANDLING */
	public void run() {
		// try {
		// player.play();
		// } catch (Exception e) {
		// e.printStackTrace();
		// }
	}
}